<?php


class Test_YuiController extends WSB_Controller_Action
{

	public function init()
	{
		parent::init();

		$navigation = $this->_helper->getHelper('Navigation');
		$navigation->add(WSB_ADMIN_URL . 'test/index/', 'Index');
		$navigation->add(WSB_ADMIN_URL . 'test/extjs/', 'EXT-JS');
		$navigation->add(WSB_ADMIN_URL . 'test/yui/', 'YUI');
		$navigation->add(WSB_ADMIN_URL . 'test/dojo/', 'Dojo');

	}

	public function preDispatch()
	{
        $this->_response->appendBody('<h1>YUI Spielereien</h1>');
        $this->_response->appendBody('<ul style="list-style-type:none;">');
        $this->_response->appendBody('<li><a href="test/yui/index/">Table</a></li>');
        $this->_response->appendBody('</ul>');
	}

	public function indexAction()
	{

		$table = new Cms_Model_DbTable_Xtension();
        $where = $table->getAdapter()->quoteInto('deleted=?', 0);
        $instances = $table->fetchAll($where);

        $this->view->rowset = $instances;
        /*
        {key:"due",label:"Due Date",formatter:YAHOO.widget.DataTable.formatDate,sortable:true},
        {key:"account",label:"Account Number", sortable:true},
        {key:"quantity",label:"Quantity",formatter:YAHOO.widget.DataTable.formatNumber,sortable:true},
        {key:"amount",label:"Amount Due",formatter:YAHOO.widget.DataTable.formatCurrency,sortable:true}
		*/
		$this->view->columns = array(
			array('key' => 'id', 'label' => 'ID', 'sortable' => 'true'),
			array('key' => 'name', 'label' => 'Name', 'sortable' => 'true'),
			array('key' => 'class', 'label' => 'Class', 'sortable' => 'true'),
			array('key' => 'icons', 'label' => '')
		);
		/*
        {key:"due", parser:YAHOO.util.DataSource.parseDate},
        {key:"account"},
        {key:"quantity", parser:YAHOO.util.DataSource.parseNumber},
        {key:"amount", parser:this.parseNumberFromCurrency}
       	*/
		$this->view->fields = array(
			array('key' => 'id'),
			array('key' => 'name'),
			array('key' => 'class'),
			array('key' => 'icons', 'callback' => array('Test_YuiController', 'green'))
		);
		/*
		{sortedBy:{key:"name",dir:"desc"}});
		*/
		$this->view->settings = array('sortedBy' => array(
			'key' => 'name', 'dir' => 'desc')
		);

	}

	public static function red($row)
	{
		return '<span style="color:red;">'.$row->id.'</span>';
	}

	public static function green($row)
	{
		return '<span style="color:green;">'.$row->id.'</span>';
	}

}
